package simulation;

import java.awt.BasicStroke;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.List;

/**
 * XXX.
 * 
 * @author Natalia R. Carvalho
 */
public class Muscle extends Spring {
    private static final int MUSCLE_STROKE = 10;
    private double myAmplitude;
    private double myTime;

    /**
     * Creates a muscle
     * @param start first mass that muscle attaches
     * @param end second mass that muscle attaches
     * @param length rest length
     * @param kVal springiness constant
     * @param amp amplitude
     */
    public Muscle(Mass start, Mass end, double length, double kVal, double amp) {
        super(start, end, length, kVal);
        myAmplitude = amp;
    }

    @Override
    public void update(double elapsedTime, Dimension bounds, List<Force> forces) {
        myTime += elapsedTime;
        super.update(elapsedTime, bounds, forces);
    }
    
    /**
     * The length of a muscle is different than the length of a spring
     */
    public double getMyLength() {
        return Math.sin(myTime * 2) * myAmplitude + super.getMyLength(); 
    }

    @Override
    public void paint(Graphics2D pen) {
        pen.setColor(getColor(Math.sin(myTime * 2)));
        pen.setStroke(new BasicStroke(MUSCLE_STROKE));
        pen.drawLine((int) getMyStart().getX(), (int) getMyStart().getY(),
                (int) getMyEnd().getX(), (int) getMyEnd().getY());
    }
}
